package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Like;
import cn.wolfcode.trip.base.domain.TInform;
import cn.wolfcode.trip.base.domain.TInformReadRecord;
import cn.wolfcode.trip.base.mapper.LikeMapper;
import cn.wolfcode.trip.base.mapper.TInformMapper;
import cn.wolfcode.trip.base.mapper.TInformReadRecordMapper;
import cn.wolfcode.trip.base.query.MessageQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMessageService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements IMessageService {
    @Autowired
    private LikeMapper likeMapper;
    @Autowired
    private TInformMapper tInformMapper;
    @Autowired
    private TInformReadRecordMapper recordMapper;
    /**
     * 每点赞一次就增加
     * @param like
     */
    @Override
    public void insertLike(Like like) {
            likeMapper.insert(like);
    }

    @Override
    public PageInfo<TInform> getSysMsg(MessageQueryObject qo) {
        qo.setOrderBy("creatTime desc");
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TInform> informs =  tInformMapper.selectByState(qo);
        return new PageInfo<>(informs);
    }

    @Override
    public void insertInform(TInform inform) {
        tInformMapper.insert(inform);
    }

    @Override
    public List<TInformReadRecord> getPriMsgUser(MessageQueryObject qo) {
        return recordMapper.getPriMsgUser(qo);
    }

    @Override
    public List<TInform> getPriMsg(MessageQueryObject qo) {

        return tInformMapper.getPriMsg(qo);
    }

    @Override
    public void insetTif(TInformReadRecord tInformReadRecord) {
        recordMapper.insert(tInformReadRecord);
    }

    @Override
    public Like checkLike(Like like) {
        Like like1=  likeMapper.checkLike(like);
        return like1;
    }

    @Override
    public void deleteLike(Like like) {
        likeMapper.deleteLike(like);
    }

    @Override
    public Integer getPriMsgNum(MessageQueryObject qo) {
        return tInformMapper.getPriMsgNum(qo);
    }

    @Override
    public void setHasRead(TInformReadRecord qo) {
        recordMapper.setHasRead(qo);
    }

    /**
     * 获取跟其中一个人的私信未读数量
     * @param qo
     * @return
     */
    @Override
    public int getOnePriMsgNum(MessageQueryObject qo) {
        return tInformMapper.getOnePriMsgNum(qo);
    }


}
